package it.unipd.dei.es1011.nucularc0d3.defaultproject.util;

import it.unipd.dei.es1011.nucularc0d3.defaultproject.R;
import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MainArrayAdapter extends ArrayAdapter<MainListViewItem> {
	
	private static int viewCount = 0;

	public MainArrayAdapter(Context context) {
		super(context, R.layout.main_listview_item, R.id.item_descript);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		boolean created = false;
		if (convertView == null) {
			created = true;
			viewCount++;
		}
		
		View view = super.getView(position, convertView, parent);

		MainListViewItem item = getItem(position);
		if (item != null) {
			ImageView iconView = (ImageView) view.findViewById(R.id.item_image);
			TextView descriptView = (TextView) view.findViewById(R.id.item_descript);

			if (created && iconView != null && item.mIcon != null) {
				iconView.setImageBitmap(item.mIcon);
			}
			if (descriptView != null && item.description != null) {
				descriptView.setTextSize(TypedValue.COMPLEX_UNIT_SP,23.0f);
				descriptView.setTextColor(Color.BLACK);
				descriptView.setText(item.description);
			}
		}

		return view;
	}
}
